The Code Project
View our advertisers Advertise with us
All Topics, .NET >> .NET Compact Framework >> Applications

Administrate SQL Server2000 From Pocket PC
By rasheed1979

This article demonstrates administrating SQL server 2000 from pocket PC on the fly. 
  Advanced
  C#, SQL
.NET CF, Windows, WinCE, .NET
PDA, Win32, SQL (SQL 2000), IIS (IIS 5), VS (VS.NET2003)
Dev, DB
  Posted 19 Feb 2005 5:25
Articles by this author
17,333 views
Search:
Ultimate Combo
MFC tools $449
Send to a friend
My Profile
My Settings
My Articles
My Bookmarks
Sign out
 


Print Broken Article? Bookmark Discuss
9 votes for this article.
Popularity: 3.6. Rating: 3.78 out of 5.

Sample Image - AdminSQLfromPocketPC.jpg

Introduction

I am a little crazy about writing mobile applications using .NET CE. This article describes about administrating SQL Server 2000 from Pocket PC with the help of Web services. Using web service I can administrate SQL server 2000 on the fly.

Client Requirements.

  1. Pocket PC with Microsoft Windows CE powered.
  2. Microsoft .NET Compact Framework 1.0.

Server Requirements.

  1. Microsoft .NET framework 1.1.
  2. MS SQL server 2000 with SP3 or above.
  3. IIS 5.0.

Background

Sometime I might away from my SQL Server or I might have be traveling somewhere. In that time, I thought about how could I control my SQL Server from there. Then I got an idea why not to try with a Pocket PC. When I stated doing the application, I faced problem in connecting to my remote SQL Server from Pocket PC. Then I look around and thought web service might be the right solution. I used web service as middle tire to interconnect my Pocket PC and SQL server. Finally, I am able to achieve that.

This is a beginning. In this, we can connect to SQL Server and manipulate query processes like how we do in Query analyzer.

In future version, I am planning to do like Desktop Enterprise Manager. If you can help me to achieve this, then you are most welcome.

Using the code

Download the source code as ZIP file. Unzip it, and in that you can find two folders named WSSQLsrv2000 and ControlSQLsrv2000.

WSSQLsrv2000 folder contains Web services, which will be consumed by the Pocket PC. Open Internet Information Services Manager (IIS) create a virtual folder under the Default Web Site directory. Set the physical file location as WSSQLsrv2000 folder path. Give write permission to the Virtual folder.

Find creating virtual folder details over here.

ControlSQLsrv2000 folder contains Windows CE application. You can compile and execute it in Emulator or deploy it in your Pocket PC.

When you execute the Pocket PC application you will be prompt for SQL server details to connect.

When you click on connect, the following code will be executed.

Login

try
{
    UpdateStatus("Connecting to the database...");
    oLoginInfo.sServer = txtServerName.Text;
    oLoginInfo.sLoginName = txtLoginName.Text;
    oLoginInfo.sPassword = txtPassword.Text;
    oLoginInfo.sDatabase = "";
    ConnectDB oConDb = new ConnectDB();
    if (oConDb.fnConnect(txtServerName.Text ,txtLoginName.Text ,txtPassword.Text))
    {
       UpdateStatus("Connected...");
       frmMain ofrmMain = new frmMain();
       ofrmMain.FillTreeView(oLoginInfo);
       ofrmMain.Show();
       this.Hide();
    }
    else
    {
       UpdateStatus("Not Connected..."); 
       .....

The following code in Web service will be executed.

[WebMethod] public bool fnConnect(string sDataSource, string sUserid, 
                                                     string sPassword)
{
   //To check the connection status with given details
   oLoginInfo.sServer = sDataSource;
   oLoginInfo.sLoginName = sUserid;
   oLoginInfo.sPassword = sPassword;
   oLoginInfo.sDatabase = "";
   if (oCon.fnConnectStatus(oLoginInfo))
   {
     //Save the details if the connection status is true for further manupulation
     SetDBConfigSettings(sDataSource,sUserid,sPassword);
     return true;
   }
   else
   { 
     //Connection failed in various reasons
     return false;
   }
 }

ConnectDB is a class written in web service. Here we are creating the object to that class and consuming its Web method fnConnect(). When this function is called, the web services receive the request and connects to the SQL server. Once the connection was success then the application will show the Server details.

We can populate the databases in two ways.

  1. Select Databases, tap and hold for few seconds and a pop up menu will appear with two options Refresh and Query Analyser. In that Select Refresh.

    Populate Database 1

  2. Select Database and select File -> Refresh From the main menu.

    Sample screenshot

Once you select the refresh option, the entire databases will be listed. Select the Database which you want to manipulate and choose the Query Analyser option based on the above two methods. Once you select it you will be redirected to another screen.

Main menu details

  1. Refresh – Reload all the databases under the server.
  2. Query Analyser – Select particular database under Databases Directory and do query manipulation by selecting this option.
  3. Re-Login – Exit from current server and login into different server.
  4. Exit – Exit and close the application.

In that text box enter the query you want to execute. For example, type

Select * from authors

Select the statement to execute. And tap on run to execute the statement. The results will be populated in the grid.

The results will be populated like this:

Results

Points of interest

When you deploy the web service in your local PC, you have to change the URL from http://localhost to http://<ipaddress> in reference.cs under WSSQLsrv2000 folder. Otherwise the Pocket PC can’t consume the service.

You can find some of my articles over here.

History

Initial version 0.1.0

About rasheed1979


Called as Rasheed. Completed Master of Computer science. Working as Software Engineer in Chennai, India.

Love to achive in different stream.

Click here to view rasheed1979's online profile.


Other popular articles:

[Top] Rate this Article for us!     PoorExcellent  

FAQ  Noise tolerance    Search comments  
  View    Per page  
New Message Msgs 1 to 11 of 11 (Total: 11) (Refresh) First Prev Next     
Subject  Author  Date 
  security   diana_01_kdr  11:38 19 Jan '06 
  Will Bluetooth work for it ??   ronithefrnd  0:30 31 Dec '05 
  Re: Will Bluetooth work for it ??   rasheed1979  2:41 2 Jan '06 
  error when deploy to pocket pc   diana_01_kdr  4:38 21 Dec '05 
  Re: error when deploy to pocket pc   rasheed1979  23:14 22 Dec '05 
  sql server ce & wifi   diana_01_kdr  12:43 19 Dec '05 
  Re: sql server ce &amp; wifi   rasheed1979  23:23 19 Dec '05 
  About Application Unconfirmed/Anonymous posting  Ali Gungormez  12:51 20 Jul '05 
  help me how to build such applications   virgo*  14:23 11 Jul '05 
  Re: help me how to build such applications   rasheed1979  6:05 12 Jul '05 
  hep me develop such application   virgo*  14:08 11 Jul '05 
Last Visit: 0:07 Saturday 1st July, 2006 First Prev Next     

General comment    News / Info    Question    Answer    Joke / Game    Admin message


All Topics, .NET >> .NET Compact Framework >> Applications
Updated: 19 Feb 2005 5:25
Article content copyright rasheed1979, 2005
everything else Copyright © CodeProject, 1999-2006.
Web01 | Advertise on The Code Project | Privacy

The Ultimate Toolbox • ASP Alliance • Developer Fusion • Developersdex • DevGuru • Programmers Heaven • Planet Source Code • Tek-Tips Forums •